﻿<navigation:Page 
    mc:Ignorable="d"
    xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"  x:Class="AdventureWorksApp.Views.EmployeePage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    xmlns:dataForm="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
    xmlns:ds="clr-namespace:AdventureWorksApp.Web"
    d:DesignWidth="640" d:DesignHeight="480"
    Title="Employee Page" 
    >
    <Grid x:Name="LayoutRoot">
        
        <riaControls:DomainDataSource 
            Name="employeeDataSource" 
            LoadSize="20" 
            QueryName="GetSalariedEmployees" 
            AutoLoad="True"
            SubmittedChanges="employeeDataSource_SubmittedChanges"
            >
            <riaControls:DomainDataSource.DomainContext>
                <ds:OrganizationContext/>
            </riaControls:DomainDataSource.DomainContext>
            <riaControls:DomainDataSource.SortDescriptors>
                <riaControls:SortDescriptor PropertyPath="VacationHours" Direction="Ascending" />
            </riaControls:DomainDataSource.SortDescriptors>
            <riaControls:DomainDataSource.FilterDescriptors>
                <riaControls:FilterDescriptor 
                     PropertyPath="VacationHours" 
                     Operator="IsGreaterThanOrEqualTo"
                     IgnoredValue=""
                     Value="{Binding ElementName=vacationHoursText, Path=Text}"  
                    >
                </riaControls:FilterDescriptor>
            </riaControls:DomainDataSource.FilterDescriptors>            
        </riaControls:DomainDataSource>

        <Grid>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="2" />
                <ColumnDefinition Width="99*" />
                <ColumnDefinition Width="2"/>
            </Grid.ColumnDefinitions>
            
            <Grid.RowDefinitions>
                <RowDefinition Height="2" />
                <RowDefinition Height="32" />
                <RowDefinition Height="30*" />
                <RowDefinition Height="32" />
                <RowDefinition Height="50*" />
                <RowDefinition Height="32" />
                <RowDefinition Height="2"/>
            </Grid.RowDefinitions>

            <StackPanel 
                Grid.Column="1"
                Grid.Row="1"
                Orientation="Horizontal" HorizontalAlignment="Left">
                <TextBlock VerticalAlignment="Center" Text="Min Vacation Hours Filter" />
                <TextBox x:Name="vacationHoursText" Width="75" FontSize="11" Margin="4" Text="0"/>
            </StackPanel>

            <sdk:DataGrid 
                Name="_grid" 
                IsReadOnly="True" 
                AutoGenerateColumns="True" 
                Grid.Column="1"
                Grid.Row="2"
                Height="Auto" MinHeight="100" 
                Width="Auto" MinWidth="400" 
                HorizontalAlignment="Left" 
                VerticalAlignment="Top" 
                ItemsSource="{Binding Data, ElementName=employeeDataSource}"
                />
            
            <sdk:DataPager 
                Name="dataPager1" 
                PageSize="5" 
                Source="{Binding Data, ElementName=employeeDataSource}"
                Grid.Column="1" Grid.Row="3" 
                Height="26" 
                Width="200"
                HorizontalAlignment="Left"
                VerticalAlignment="Top" 
                 />

            <StackPanel 
                Grid.Column="1" Grid.Row="3" 
                Width="300"
                Orientation="Horizontal" 
                HorizontalAlignment="Left" 
                VerticalAlignment="Top"
                Margin="210,2,0,0"
                >
                <Button 
                    x:Name="addNewEmployee" 
                    Width="90" Height="23"
                    Content="Add Employee"  
                    Margin="4,0,0,0" Click="addNewEmployee_Click" />
            </StackPanel>

            <dataForm:DataForm 
                x:Name="dataForm1" 
                Grid.Column="1" Grid.Row="4"
                Width="Auto" MinWidth="400"
                Header="Employee Information"
                AutoGenerateFields="False" 
                AutoEdit="False" AutoCommit="False" 
                CurrentItem="{Binding SelectedItem, ElementName=_grid}" Margin="0,12,0,0">
                <dataForm:DataForm.EditTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <dataForm:DataField Label="Employee ID">
                                <TextBox IsReadOnly="True" Text="{Binding BusinessEntityID, Mode=OneWay}" />
                            </dataForm:DataField>
                            <dataForm:DataField Label="Login ID">
                                <TextBox Text="{Binding LoginID, Mode=TwoWay}" />
                            </dataForm:DataField>
                            <dataForm:DataField Label="Hire Date">
                                <TextBox Text="{Binding HireDate, Mode=TwoWay}" />
                            </dataForm:DataField>
                            <dataForm:DataField Label="Marital Status">
                                <TextBox Text="{Binding MaritalStatus, Mode=TwoWay}" />
                            </dataForm:DataField>
                            <dataForm:DataField Label="Gender">
                                <TextBox Text="{Binding Gender, Mode=TwoWay,NotifyOnValidationError=True,  ValidatesOnExceptions=True }"  />
                            </dataForm:DataField>
                            <dataForm:DataField Label="Vacation Hours">
                                <TextBox Text="{Binding VacationHours, Mode=TwoWay,NotifyOnValidationError=True,  ValidatesOnExceptions=True }"  />
                            </dataForm:DataField>
                            <dataForm:DataField Label="Sick Leave Hours">
                                <TextBox Text="{Binding SickLeaveHours, Mode=TwoWay,NotifyOnValidationError=True,  ValidatesOnExceptions=True }"  />
                            </dataForm:DataField>
                            <dataForm:DataField Label="Active">
                                <CheckBox IsChecked="{Binding CurrentFlag, Mode=TwoWay,NotifyOnValidationError=True,  ValidatesOnExceptions=True }"  />
                            </dataForm:DataField>
                        </StackPanel>
                    </DataTemplate>
                </dataForm:DataForm.EditTemplate>
            </dataForm:DataForm>

            <StackPanel 
                Grid.Column="1" Grid.Row="5"
                Orientation="Horizontal" 
                HorizontalAlignment="Left" 
                Margin="0,2,0,0">
                <Button 
                    x:Name="submitButton" 
                    Width="75" Height="23" 
                    Content="Submit" 
                    Margin="4,0,0,0" 
                    Click="submitButton_Click"/>
                <Button 
                    x:Name="approveSabbatical" 
                    Width="145" 
                    Height="23"  
                    Content="Approve Sabbatical false"  
                    Margin="4,0,0,0" Click="approveSabbatical_Click" />
                <Button 
                    x:Name="approveSabbatical2" 
                    Width="145" 
                    Height="23"  
                    Content="Approve Sabbatical true"  
                    Margin="4,0,0,0" Click="approveSabbatical2_Click" />
            </StackPanel>

        </Grid>

    </Grid>
</navigation:Page>
